/*
 *  Copyright 2007 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.webapp.form.core;

import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>Form for layout with containers.</p>
 * <p><a href="LayoutWithContainersForm.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.4 $ $Date: 2008/04/29 17:52:51 $
 * @struts.form name="layoutWithContainersForm"
 */
public class LayoutWithContainersForm extends LayoutForm {

    Map availableListsMap = new HashMap();
    Map selectedListsMap = new HashMap();
    Map availableArraysMap = new HashMap();
    Map selectedArraysMap = new HashMap();

    public Map getAvailableTileListComponentsListsMap() {
        return availableListsMap;
    }

    public void setAvailableTileListComponentsListsMap(Map listsMap) {
        this.availableListsMap = listsMap;
    }

    public Map getAvailableTileListComponentsMap() {
        return availableArraysMap;
    }

    public void setAvailableTileListComponentsMap(Map arraysMap) {
        this.availableArraysMap = arraysMap;
    }

    public java.util.List getAvailableTileListComponentsList(String id) {
        return ensureNotNull((java.util.List) availableListsMap.get(id));
    }

    public void setAvailableTileListComponentsList(String id, java.util.List list) {
        availableListsMap.put(id, list);
    }

    public String[] getAvailableTileListComponents(String id) {
        return (String[]) availableArraysMap.get(id);
    }

    public void setAvailableTileListComponents(String id, String[] array) {
        availableArraysMap.put(id, array);
    }

    public Map getSelectedTileListComponentsListsMap() {
        return selectedListsMap;
    }

    public void setSelectedTileListComponentsListsMap(Map listsMap) {
        this.selectedListsMap = listsMap;
    }

    public Map getSelectedTileListComponentsMap() {
        return selectedArraysMap;
    }

    public void setSelectedTileListComponentsMap(Map arraysMap) {
        this.selectedArraysMap = arraysMap;
    }

    public java.util.List getSelectedTileListComponentsList(String id) {
        return ensureNotNull((java.util.List) selectedListsMap.get(id));
    }

    public void setSelectedTileListComponentsList(String id, java.util.List list) {
        selectedListsMap.put(id, list);
    }

    public String[] getSelectedTileListComponents(String id) {
        return (String[]) selectedArraysMap.get(id);
    }

    public void setSelectedTileListComponents(String id, String[] array) {
        selectedArraysMap.put(id, array);
    }

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        super.reset(mapping, request);
        this.availableListsMap = new HashMap();
        this.selectedListsMap = new HashMap();
        this.availableArraysMap = new HashMap();
        this.selectedArraysMap = new HashMap();
    }

    /**
     * If argument is null, returns empty list.
     *
     * @param list list to work with
     * @return not null list
     */
    protected List ensureNotNull (List list) {
        if (list == null) {
            list = new ArrayList();
        }
        return list;
    }
}
